package com.baosight.sczx.zm.ch.service;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.ch.domain.ZMCHPlanValidateData;

/**
 * 
 * <p>Title: ServiceZMCH91.java</p>
 * <p>Description: 从ZMCH90-ZMCHF0所有验收的从表</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2016年9月30日 上午9:56:17  郭淑芳  Create
 *</pre>
 */
public class ServiceZMCH91 extends ServiceEPBase {
	
	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始进入方法</p>
	 * <p>return value: ServiceZMCH91</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月30日上午9:56:06 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");// 如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: 查询方法</p>
	 * <p>return value: ServiceZMCH91</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月30日上午9:55:55 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdForeignId = inInfo.getString("fdForeignId");
		StaticTools.setQueryParameters(inInfo, "fdForeignId", fdForeignId, true);

		EiInfo outInfo = super.query(inInfo, "ZMCHPlanValidateData.query", new ZMCHPlanValidateData());
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.ch.planValidateData", false));// 验收类型
		outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cp.department", "orgCode", "orgName", false, UserSession.getInSessionProperty("miningCode").toString()));

		return outInfo;
	}

	/**
	 * 
	 * <p>Function: insert</p>
	 * <p>Description: 新增方法</p>
	 * <p>return value: ServiceZMCH91</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月30日上午9:55:46 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		String fdForeignId = inInfo.getString("fdForeignId");
		EiInfo out = new EiInfo();
		ZMCHPlanValidateData _dom = new ZMCHPlanValidateData();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		for (int i = 0; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			_dom.setFdForeignId(fdForeignId);
			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CH_PLANVALIDATEDATA"));
			this.dao.insert("ZMCHPlanValidateData.insert", _dom);
		}

		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}

	/**
	 * 
	 * <p>Function: update</p>
	 * <p>Description: 修改方法</p>
	 * <p>return value: ServiceZMCH91</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月30日上午9:55:35 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo out = new EiInfo();
		ZMCHPlanValidateData _dom = new ZMCHPlanValidateData();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));

			this.dao.update("ZMCHPlanValidateData.update", _dom);
		}

		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}
	
	/**
	 * 
	 * <p>Function: delete</p>
	 * <p>Description: 删除方法</p>
	 * <p>return value: ServiceZMCH91</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月30日上午9:55:24 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo _temp = super.delete(inInfo, "ZMCHPlanValidateData.delete");

		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());

		return out;
	}	
} 